package com.blankii.androidlibrary.exts

import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData

fun <T> LiveData<T>.combineWith(other: LiveData<T>, block: (T?, T?) -> Boolean): LiveData<Boolean> {
    val result = MediatorLiveData<Boolean>()

    result.addSource(this) { value1 ->
        result.value = block(value1, other.value)
    }

    result.addSource(other) { value2 ->
        result.value = block(this.value, value2)
    }

    return result
}